package testSpringMVC;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.xiangxu.telecom.cost.dao.CostDao;
import cn.xiangxu.telecom.cost.dao.CostDaoJdbcImpl;
import cn.xiangxu.telecom.cost.entity.CostInfo;
import cn.xiangxu.telecom.cost.service.CostService;
import cn.xiangxu.telecom.cost.service.CostServiceImpl;
import cn.xiangxu.telecom.login.dao.AdminDao;
import cn.xiangxu.telecom.login.dao.AdminDaoJdbcImpl;
import cn.xiangxu.telecom.login.entity.Admin;
import cn.xiangxu.telecom.login.service.AdminService;
import cn.xiangxu.telecom.login.service.AdminServiceImpl;

public class testSpringMVC {
	@Test
//	测试配置文件的bean是否配置成功
	public void test01() {
		String config = "spring-mvc.xml";
		ApplicationContext  ac = new ClassPathXmlApplicationContext(config);
		System.out.println(ac);
		
		Properties p = ac.getBean("config", Properties.class);
		System.out.println(p);
		System.out.println(p.getProperty("url"));
		
	}
	
	@Test
//	测试连接池配置
	public void test02() {
		String config = "spring-mvc.xml";
		ApplicationContext  ac = new ClassPathXmlApplicationContext(config);
		
		DataSource ds = ac.getBean("dbcp", BasicDataSource.class);
		System.out.println(ds);
	}
	
	@Test
//	测试 AdminDao
	public void test03() {
		String config = "spring-mvc.xml";
		ApplicationContext  ac = new ClassPathXmlApplicationContext(config);
		
		AdminDao ad = ac.getBean("adminDao", AdminDaoJdbcImpl.class);
		Admin admin = ad.findByAdminCode("caocao");
		System.out.println(admin);
		
	}
	
	@Test
//	测试adminService
	public void test04() {
		String config = "spring-mvc.xml";
		ApplicationContext  ac = new ClassPathXmlApplicationContext(config);
		
		AdminService as = ac.getBean("adminService", AdminServiceImpl.class);
		Admin admin = as.checkAdminInfo("caocao", "123");
		System.out.println(admin);
	}
	
	@Test
//	测试costDao
	public void test05() {
		String config = "spring-mvc.xml";
		ApplicationContext  ac = new ClassPathXmlApplicationContext(config);
		
		CostDao cd = ac.getBean("costDao", CostDaoJdbcImpl.class);
		List<CostInfo> list = cd.findAllCost();
		for(CostInfo cost : list) {
			System.out.println(cost);
		}
	}
	
	@Test
//	测试costService
	public void test06() {
		String config = "spring-mvc.xml";
		ApplicationContext  ac = new ClassPathXmlApplicationContext(config);
		
		CostService cs = ac.getBean("costService", CostServiceImpl.class);
		List<CostInfo> list = cs.checkNull();
		
		for(CostInfo ci : list) {
			System.out.println(ci);
		}
	}
	
}

















